package com.binyouwei.designpatterns.structural_type.flyweight;

import java.util.HashMap;

/**
 * @author 宾有为
 * @date 2024/7/8 17:10
 * @link https://blog.csdn.net/baidu_41616022?type=blog
 * @describe：用于生成基于给定信息的实体类对象
 **/
public class ShapeFactory {
    private static final HashMap<String,FlyweightShape> circleMap = new HashMap<>();

    public static FlyweightShape getCircle(String color) {
        FlyweightCircle circle = (FlyweightCircle) circleMap.get(color);
        if (circle == null) {
            circle = new FlyweightCircle(color);
            circleMap.put(color, circle);
            System.out.println("Creating circle of color : " + color);
        }
        return circle;
    }
}
